package com.xll.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xll.entity.Order;
import com.xll.entity.TravelBook;
import com.xll.mapper.TravelBookMapper;
import com.xll.service.TravelBookService;
import com.xll.utils.PageResult;
import com.xll.utils.QueryInfo;
import com.xll.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
@Slf4j
public class TravelBookServiceImpl implements TravelBookService {

    private  final TravelBookMapper travelBookMapper;

    public TravelBookServiceImpl(TravelBookMapper travelBookMapper) {
        this.travelBookMapper = travelBookMapper;
    }

    @Override
    public Result insert(TravelBook travelBook) {
        travelBookMapper.insert(travelBook);
        return Result.success("景区预订成功");
    }

    @Override
    public Result findByUserId(Long userId) {
        if(userId==null){
            return  Result.fail("请传入id");
        }
        List<TravelBook> byUserId = travelBookMapper.findByUserId(userId);
        return Result.success("获取预售信息成功",byUserId);
    }

    @Override
    public Result findPage(QueryInfo queryInfo) {
        PageHelper.startPage(queryInfo.getPageNumber(), queryInfo.getPageSize());
        Page<TravelBook> page = travelBookMapper.findPage(queryInfo.getQueryString());
        return Result.success("订单信息查询成功", new PageResult(page.getTotal(), page.getResult()));
    }
}
